<template>
	<view class="inv_records">
		<!-- <u-calendar v-model="show" mode="range" btn-type='success' range-color='#26C281'
			range-bg-color='rgba(38, 194, 129, 0.13)' active-bg-color='#26C281' :safe-area-inset-bottom='true'
			@change="change"></u-calendar> -->

		<view class="header-card">

			<view class="words">
				您对本平台使用过程中如有任何问题（如套餐内容、佣金结算、添加代理等），请联系您的专属服务经理。
			</view>
			<view class="mobile">
				<text>电话号：{{superiors_mobile}}</text>
				<view class="r-btn" @click.stop="copyBtn(superiors_mobile)">复制</view>
			</view>
			<view class="wechat">
				<text>微信号：{{superiors_wx}}</text>
				<view class="r-btn" @click.stop="copyBtn(superiors_wx)">复制</view>
			</view>
			
			<view class="wechat-nav">
				<view class="mini-r-btn" @click="yongjinShow = true">推广奖励设置说明</view>
				<view class="mini-r-btn" @click="receiptBtn">设置您的推广佣金</view>
			</view>
		</view>
		<view class="team_top">
			<view class="nav">
				<!-- <view class="left" @click="show=true">
					<text class="time" :class="startTime?'time_active':''">{{startTime?startTime:'开始时间'}}</text>
					<text class="line">-</text>
					<text class="time" :class="endTime?'time_active':''">{{endTime?endTime:'结束时间'}}</text>
				</view> -->
				<!-- <view class="btn" @click="txtNavBtn(5,0)">添加代理</view>
				<view class="btn" @click="useSearch">代理查询</view>
				<view class="btn">代理人数：{{total}}</view> -->
				<view class="btn" @click="txtNavText(5)">代理必读</view>
				<view class="btn" @click="goPath('/pages/order/CreatePoster')">邀请下级</view>
				<view class="btn" @click="txtNavBtn(5,0)">添加下级</view>
				<view class="btn" @click="useSearch">下级查询 {{total}}</view>
			</view>
			
			
			<view class="nav">
				<!-- <view class="left" @click="show=true">
					<text class="time" :class="startTime?'time_active':''">{{startTime?startTime:'开始时间'}}</text>
					<text class="line">-</text>
					<text class="time" :class="endTime?'time_active':''">{{endTime?endTime:'结束时间'}}</text>
				</view> -->
				<!-- <view class="btn" @click="txtNavBtn(5,0)">添加代理</view>
				<view class="btn" @click="useSearch">代理查询</view>
				<view class="btn">代理人数：{{total}}</view> -->
				
				<!-- <view class="nav-left">
					<view class="btn btn-mini" @click="handeloTyxg()"  v-if="!tyShow">批量操作</view>
					<view class="btn btn-mini" @click="handelxia()" v-if="tyShow">下架至卡品仓</view>
					<view class="btn btn-mini" @click="handelshang()" v-if="tyShow">上架至售卖中</view>
					<view class="btn btn-mini" @click="handelquxiao()" v-if="tyShow">取消</view>
				</view> -->
				<!-- <view class="btn" @click="txtNavBtn(5,0)">添加下级</view>
				<view class="btn" @click="useSearch">下级查询 {{total}}</view> -->
			</view>
			
			<!-- <view class="user-box">
			<u-button size="mini" type="success">批量操作</u-button>
				<u-button style="float: right;" size="mini" type="success">设置您的推广佣金</u-button>
			</view> -->
			<view class="search_box" v-show="search">
				<u-form>
					
					<u-form-item>
						<u-input placeholder="请输入账号" v-model="query.username"  maxlength="40" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入姓名" v-model="query.nickname"  maxlength="11" border></u-input>
					</u-form-item>
					<u-form-item>
						<u-input placeholder="请输入电话号码" v-model="query.phone"  maxlength="40" border></u-input>
					</u-form-item>
					<u-form-item>
						<view class="btn_box">
							<u-button shape="circle" type="error" class="btn reset" @click="reset">重置</u-button>
							<u-button shape="circle" class="btn confirm" @click="confirm">查询</u-button>
						</view>
					</u-form-item>
				</u-form>
			</view>
			<!-- <view class="nav_list">
				<u-tabs :list="navList" height='88' active-color='#26C281' inactive-color='#222222' :is-scroll="false" :current="current" @change="navChange"></u-tabs>
			</view> -->
		</view>

		<view class="no_html" v-if="list.length==0">
			<image src="@/static/images/no_img5.png" mode=""></image>
			<text>没有数据</text>
		</view>
		<!--  -->
		<view v-else>
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="text-header">
					<text class="left topword">{{item.username}}</text>
					<text class="right">可提现{{item.money}}元</text>
				</view>
				<view class="user">					
						<view class="item">代理姓名：{{item.nickname}}</view>
						<view class="item">手机号：{{item.mobile}}</view>
						<view class="item order_num"><text>本月订单数：{{item.month_order}}</text><text>全部订单数：{{item.all_order}}</text></view>
						<view class="item">登录时间：{{item.logintime_text}}</view>
						<view class="item">创建时间：{{item.createtime_text}}</view>					
				</view>
				<view class="btns">
					<view>
						<u-checkbox v-if="tyShow" v-model="item.checked" shape="circle" active-color="#26C281" style="font-weight: bold;"></u-checkbox>
					</view>
					<text class="btn" @click="txtNavBtn(1,item.id)">修改密码</text>
					<!-- <text class="btn" @click="txtNavBtn(2,item.id,item.nickname)">设置佣金</text> -->
					<text class="btn" @click="txtNavBtn(3,item.id)">佣金设置</text>
					<text class="btn" @click="txtNavBtn(4,item.id)">全部订单</text>
				</view>
			</view>
			<view class="mall_loading" v-if="list.length" style="padding-top: 24rpx;">
				<u-loadmore :status="status" color='#999' />
			</view>
		</view>
		<ConfirmReceipt ref="confirm_receipt" @submit='submitBtn'></ConfirmReceipt>
		
		<u-popup v-model="yjShow" mode="center" border-radius="16" width="600rpx" height="400rpx">
			<view class="confirm_box">
				<view class="title">请设置您得到的推广佣金</view>
				
				<view style="flex: 1;">
					<view class="text" style="padding:40rpx 30rpx; display: flex; align-items: center;">
						<view style="font-size: 28rpx; margin-right: 20rpx;">佣金差价:</view>
						<view class="define-btn">
							<u-input class="input-c" v-model="params.money" type="text" :clearable='false' :placeholder="'请输入佣金差价'" />
							<view class="input-btn" @click="defineBtn">确定</view>
						</view>
					</view>
				</view>
				
				<view class="btn">
					<text class="btn_left" @click="yjShow=false">取消</text>
					<!-- <text class="btn_right" @click="defineBtn">确定</text> -->
				</view>
			</view>
		</u-popup>
		
		<u-popup v-model="yongjinShow" mode="center" border-radius="16" width="590rpx" height="900rpx">
			<view class="gy-center-title">佣金修改说明</view>
			<scroll-view :scroll-y="true" class="gy-center goods-tz-content">
				<u-parse :html="configData.xiaji_yongjin_content"></u-parse>
			</scroll-view>
			<view class="gy-bottom" @click="yongjinShow = false">我知道</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import ConfirmReceipt from '@/components/confirm_receipt/confirm_receipt.vue';
	export default {
		components: {
			ConfirmReceipt
		},
		data() {
			return {
				show: false,
                navList: [{
                					name: '待收货'
                				}, {
                					name: '待付款'
                				}, {
                					name: '待评价'
                				}],
				current: 0,
				id: '',
				info: '',
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				page: 1,
				list: [],
				total:'',
				superiors_mobile:'',
				superiors_wx:'',
				query: {
					username: "",
					nickname: "",
					phone: ""
				},
				search: false,
				tyShow: false,
				yjShow: false,
				yongjinShow: false,
				configData: {},
				params: {
					money: 3
				},
				commission_acquiesce:3,
				tyShowList: [
					{
						value: '1',
						label: '下架至卡品仓'
					},
					{
						value: '2',
						label: '上架至售卖中'
					}
				]
			};
		},
		onLoad(opt) {
			if (opt.id) {
				this.id = opt.id
			}
			this.$httpApi.indexConfig().then(res => {
				this.configData = res.data
			})
		},
		onShow() {
			this.page = 1
			this.getList()
		},
		// onHide(){
		// 	this.$refs.confirm_receipt.closeBtn()
		// },
		methods: {
			defineBtn() {
				this.$httpApi.team_all_money({
					isRecords: 1,
					...this.params,
				}).then((res)=>{
					this.$tips.hideLoading()
					if(res.code==1){
						this.id=''
						this.yjShow = false
					}
				})
			},
			// 修改佣金
			receiptBtn(val, rebate) {
				this.yjShow = true
			},
			handeloTyxg() {
				this.tyShow = true
			},
			handelquxiao() {
				this.tyShow = false
			},
			handelxia() {
				const checkedids = this.list.filter(item => item.checked).map(i => i.id)
				if(checkedids.length == 0) {
					this.$tips.showToast('请选择要放入卡品仓库的信息')
					return
				}
				const ids = checkedids.join(',')
				this.xiajia(ids, 1)
			},
			xiajia(ids,status) {
				var that = this
				var content = "确认放入仓库吗？";
				if(status == 2){
					content = "确认上架吗？";
				}
				uni.showModal({
				    title: '提示',
				    content: content,
				    success: function (res) {
				        if (res.confirm) {
				            var params = {
								isRecords: 1,
				            	ids: ids,
				            	agent_id: that.ids,
				            	status:status
				            }
				            that.$httpApi.soldout(params).then((res) => {
				            	if (res.code == 1) {
				            		that.$tips.showToast('操作成功')
				            		window.location.reload()
				            	}
				            })
				        } 
				    }
				});
			
				
				
			},
			handelshang() {
				const checkedids = this.list.filter(item => item.checked).map(i => i.id)
				if(checkedids.length == 0) {
					this.$tips.showToast('请选择要售卖中的信息')
					return
				}
				const ids = checkedids.join(',')
				this.xiajia(ids, 2)
			},
			goPath(url) {
				uni.navigateTo({
					url: url
				})
			},
			
			/**
			 * 点击查询
			 */
			useSearch() {
				this.search = !this.search
			},
			
			/**
			 * 重置
			 */
			reset() {
				this.query = {
					nickname: "",
					username: "",
					phone: ""
				}
				this.getList()
			},
			
			/**
			 * 点击搜索
			 */
			confirm() {
				this.page = 1 
				this.getList()
			},
			
			copyBtn(txt) {
			
				uni.setClipboardData({
					data: txt,
					success: function() {
						console.log('success');
					}
				});
			},
			// 列表
			getList() {
				let { query } = this 
				var that = this
				if (that.page == 1) {
					that.$tips.showLoading('加载中')
				} else {
					that.status = 'loading'
				}
				var params = {
					username: that.username,
					nickname: that.nickname,
					mobile: that.mobile,
					...query,
				}
				that.$httpApi.userScorelogIndex(params).then((res) => {
					if (res.code == 1) {
						if (that.page == 1) {
							that.list = []
							that.$tips.hideLoading()
						}
						if (res.data.current_page == res.data.last_page) {
							that.status = 'nomore'
						} else {
							that.status = 'loadmore'
						}
						that.params.money =res.data.commission_acquiesce
						that.list = that.list.concat(res.data.data)
						that.total = res.data.total
						that.superiors_wx = res.data.superiors_wx
						that.superiors_mobile = res.data.superiors_mobile
						
						if(res.data.is_tan) {
							that.txtNavBtn(2)
						}
					}
				})
			},
			// 查询
			queryBtn() {
				this.page = 1
				this.getList()
			},
			txtNavText(type) {
				if(type == 5){
					uni.navigateTo({
						url:'/pages/order/text-list?m_type=3'
					})
				}else{
					uni.navigateTo({
						url:'/pages/other/text?type='+type
					})
				}
				
			},
			txtNavBtn(type, ids, nickname = '') {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/person/agent_info?ids=' + ids
					})
				} else if (type == 2) {

					this.$refs.confirm_receipt.openBtnThree(ids, nickname)
				} else if (type == 3) {
					uni.navigateTo({
						url: '/pages/order/order?ids=' + ids
					})
				} else if (type == 5) {
					uni.navigateTo({
						url: '/pages/person/agent_add'
					})
				} else if(type==4){
					
					uni.navigateTo({
						url: '/pages/order/orderdaili?ids='+ids
					})
				}else{
					uni.navigateTo({
						url: '/pages/order/orderdaili?ids='+ids
					})
				}
			},

			// 切换
			navChange(index) {
				this.current = index
				this.page = 1
				this.getList()
			},
			// 选择日期
			change(e) {
				this.startTime = e.startDate
				this.endTime = e.endDate
			}
		},
		onReachBottom() {
			if (this.status == 'nomore' || this.status == 'loading') {
				return
			}
			this.page++
			this.getList()
		},
	}
</script>

<style lang="less">
	.define-btn {
		flex: 1;
		display: flex;
		align-items: center;
		border: 1rpx solid #e5e5e5;
		border-radius: 10rpx;
		
		
		.input-c {
			flex: 1;
			padding: 0 20rpx !important;
		}
		.input-btn {
			border-left: 1rpx solid #e5e5e5;
			font-size: 28rpx;
			padding: 20rpx;
		}
	}
	.gy-center-title {
		padding: 20rpx 0;
		text-align: center;
		font-weight: 700;
		color: #000000;
	}
	.gy-center {
		padding: 0 30rpx;
	}
	.gy-center-p {
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		line-height: 42rpx;
		color: #666;
		
	}
	.gy-center-p-border {
		border-bottom: 1rpx solid #e5e5e5;
	}
	.gy-content {
		height: 840rpx;
		overflow-y: auto;
	}
	.goods-tz-content {
		box-sizing: border-box;
		height: 700rpx;
		overflow-y: auto;
		cursor: pointer;
	}
	.gy-bottom {
		border-top: 1rpx solid #e5e5e5;
		text-align: center;
		padding-top: 50rpx;
		color: #148EFF;
	}
	
	.search_box {
		width: 100%;
		padding: 0 40rpx;
		.btn_box {
			width: 100%;
			display: flex;
			justify-content: center;
			.btn {
				margin: 10rpx;
				width: 160rpx;
			}
			.confirm {
				background-color: #00afaa;
				color: #fff;
			}
		}
	}
	.topword {
		color: #dd0000 !important
	}

	.inv_records {
		width: 100%;

		.header-card {
			margin: 20rpx;
			background: #26C281;
			padding: 20rpx;
			color: #fff;
			border-radius: 10rpx;
			.words{ text-indent: 48rpx;padding:20rpx}

			.mobile {
				padding: 20rpx 0;
				width: 400rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 auto;
				.r-btn{border:1rpx solid #fff;border-radius: 6rpx;padding:6rpx 20rpx;}
			}

			.wechat {
				padding: 20rpx 0;
				width: 400rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 auto;
				.r-btn{border:1rpx solid #fff;border-radius: 6rpx;padding:6rpx 20rpx;}
			}
			.wechat-nav {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
			}
			.mini-r-btn {
				border: 1rpx solid #fff;
				border-radius: 6rpx;
				padding: 6rpx 20rpx;
				margin-right: 20rpx;
			}
		}

		.team_top {
			width: 100%;
			background: #fff;
			border-bottom: 2rpx solid #f7f8fa;

			.nav {
				width: 100%;
				height: 100rpx;
				padding: 20rpx 32rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				
				.nav-left {
					display: flex;
					align-items: center;
				}
				.btn-mini {
					// padding: 8rpx 13rpx !important;
					// font-size: 24rpx;
					margin-right: 10rpx;
				}

				.left {
					width: 538rpx;
					height: 64rpx;
					padding: 0 30rpx;
					background: #F5F5F5;
					border-radius: 32rpx;
					display: flex;
					align-items: center;
					justify-content: space-around;

					.line {
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #BEBEBE;
					}

					.time {
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #BEBEBE;
					}

					.time_active {
						color: #333;
					}
				}
                .btn{color: #FFFFFF;
					background: #26C281;
					border-radius: 32rpx;
					padding:15rpx 25rpx;
					text-align: center;
					}
				.right {
					width: 132rpx;
					height: 64rpx;
					line-height: 64rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					background: #26C281;
					border-radius: 32rpx;
				}
			}

			.nav_list {
				width: 100%;
				border-bottom: 2rpx solid #f7f8fa;
			}
		}

		.num_list {
			width: 100%;
			margin-bottom: 23rpx;
			padding: 24rpx 0;
			background: #fff;
			display: flex;
			justify-content: space-between;

			.txt {
				flex: 1;
				// width: 100%;
				border-left: 2rpx solid #f7f8fa;

				text {
					display: block;
					width: 100%;
					text-align: center;
				}

				.t_num {
					font-size: 32rpx;
					font-family: OPPOSans-Bold, OPPOSans;
					font-weight: bold;
					color: #222222;
				}

				.t_tip {
					padding-top: 8rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}

			.txt:first-child {
				border-left: none;
			}
		}

		.list {

			margin-top: 1rpx;
			padding: 8rpx 32rpx 32rpx;
			background: #fff;
			margin: 20rpx;
			border-radius: 10rpx;

			.user {
				.item{color:#666;padding:6rpx 0;}
				.order_num{
					display:flex;
					text{
						margin-right:40rpx
					}
				}
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;

				.btn {
					margin: 20rpx 8rpx;
					border-radius: 6rpx;
					border: 1rpx solid #eee;
					padding: 12rpx 18rpx;
					margin-top: 30rpx;
				}
			}

			.text-header {
				width: 100%;
				padding: 24rpx 0;
				display: flex;
				justify-content: space-between;

				.left {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222222;
				}

				.right {
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #999999;
				}

				.color1 {
					color: #FF6230;
				}

				.color2 {
					color: #26C281;
				}
			}
		}
	}
	
	
	.max-money {
		text-align: left;
		font-weight: 400;
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}
	.confirm_box{
		width: 100%;
		height: 100%;
		padding: 40rpx 0;
		background: red;
		background: linear-gradient(to bottom, rgba(38, 194, 129, 0.20), rgba(38, 194, 129, 0), rgba(38, 194, 129, 0));
		display: flex;
		// justify-content: space-between;
		flex-direction: column;
		.title{
			width: 100%;
			font-size: 36rpx;
			text-align: center;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #222222;
		}
		.sub-title {
			font-size: 26rpx;
			font-weight: 400;
			text-align: center;
		}
		.text{
			width: 100%;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #666666;
		}
		.btn{
			width: 100%;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			text{
				display: block;
				width: 247rpx;
				height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.btn_left{
				color: #999;
				border: 1px solid #999999;
			}
			.btn_right{
				color: #fff;
				background: #26C281;
			}
		}
	}
</style>